<template>
  <div class="container">
    <div class="swiper">
      <van-swipe @change="onChange" autoplay="3000">
        <van-swipe-item
          v-for="(item,index) in productDetail.product.product_img"
          :key="index"
          :style="{'background-color':'#' + index + '10' + index}"
        >
          <img v-lazy="item" alt />
        </van-swipe-item>
        <template #indicator>
          <div class="custom-indicator">
            <span>{{ current + 1 }}/</span>
            {{productDetail.product.product_img.length}}
          </div>
        </template>
      </van-swipe>
    </div>
    <div class="info">
      <div class="title">
        <p>
          <span v-show="productDetail.product.product_area">{{productDetail.product.product_area}}</span>
          {{productDetail.product.product_name}} {{productDetail.product.product_place}}
        </p>
      </div>
      <div class="price">
        <span>￥</span>
        <span>{{productDetail.product.product_price}}</span>
        <span v-show="productDetail.product.product_unit">/{{productDetail.product.product_unit}}</span>
      </div>
      <div class="time_address">
        <p>
          <img src="../assets/goods/time.png" alt="#" />
          更新时间：{{productDetail.product.origin_product_update_time | parseTime }}
        </p>
        <p>
          <img src="../assets/goods/address.png" alt />
          {{productDetail.product.product_warehouse }}
        </p>
      </div>
    </div>
    <div class="num">
      <div class="info-item">
        <div class="name">可售量</div>
        <div class="text">
          {{Number(productDetail.product.real_stock) .toFixed(4)}}
          <span
            v-show="productDetail.product.product_unit"
          >{{productDetail.product.product_unit}}</span>
        </div>
      </div>
      <div class="info-item">
        <div class="name">起售量</div>
        <div class="text">
          {{Number(productDetail.product.start_number) .toFixed(4)}}
          <span
            v-show="productDetail.product.product_unit"
          >{{productDetail.product.product_unit}}</span>
        </div>
      </div>
      <!-- <div class="info-item">
        <div class="name">支付方式</div>
        <div class="text">{{productDetail.agent.agent_pay_way ? '一次性支付':'按月支付'}}</div>
      </div>-->
    </div>
    <div class="detail">
      <div class="detail-item" @click="()=>{this.showPopup = true}">
        参数详情
        <van-icon class="icon" name="arrow" />
      </div>
    </div>
    <div class="footer">
      <div class="agent-btn" @click="handleBack">返回</div>
    </div>
    <van-popup v-model="showPopup" position="bottom">
      <div v-if="productDetail.product.product_type == 1" class="popup-content">
        <div class="title">参数详情</div>
        <div class="item border-b">
          <div class="name">区域</div>
          <div class="text">{{productDetail.product.product_area}}</div>
        </div>
        <div class="item border-b">
          <div class="name">产地</div>
          <div class="text">{{productDetail.product.product_place}}</div>
        </div>
        <div class="item border-b">
          <div class="name">品名</div>
          <div class="text">{{productDetail.product.product_name}}</div>
        </div>
        <div class="item border-b">
          <div class="name">形态</div>
          <div class="text">{{productDetail.product.product_style}}</div>
        </div>
        <div class="item border-b">
          <div class="name">规格</div>
          <div class="text">{{productDetail.product.product_sku}}</div>
        </div>
        <div class="item border-b">
          <div class="name">等级</div>
          <div class="text">{{productDetail.product.product_level}}</div>
        </div>
        <div class="item border-b">
          <div class="name">所在仓库</div>
          <div class="text">{{productDetail.product.product_warehouse }}</div>
        </div>
        <div class="item border-b">
          <div class="name">是否含税</div>
          <div class="text">否</div>
        </div>
        <div class="item border-b">
          <div class="name">发布时间</div>
          <div class="text">{{productDetail.product.origin_product_create_time | parseTime }}</div>
        </div>
        <img
          class="close"
          @click="()=>{this.showPopup = false}"
          src="../assets/goods/close_03.png"
          alt="#"
        />
        <div class="footer">
          <div class="btn" @click="()=>{this.showPopup = false}">完成</div>
        </div>
      </div>

      <div v-else class="popup-content">
        <div class="title">参数详情</div>
        <div class="item border-b">
          <div class="name">商品标题</div>
          <div class="text">{{productDetail.product.title}}</div>
        </div>
        <div class="item border-b">
          <div class="name">品牌</div>
          <div class="text">{{productDetail.product.product_brand}}</div>
        </div>
        <div class="item border-b">
          <div class="name">风格</div>
          <div class="text">{{productDetail.product.product_furniture_style}}</div>
        </div>
        <div class="item border-b">
          <div class="name">类型</div>
          <div class="text">{{productDetail.product.furniture_category}}</div>
        </div>
        <div class="item border-b">
          <div class="name">材质</div>
          <div class="text">{{productDetail.product.product_material}}</div>
        </div>
        <div class="item border-b">
          <div class="name">规格</div>
          <div class="text">{{productDetail.product.product_sku}}</div>
        </div>
        <div class="item border-b">
          <div class="name">所在仓库</div>
          <div class="text">{{productDetail.product.product_warehouse }}</div>
        </div>
        <div class="item border-b">
          <div class="name">是否含税</div>
          <div class="text">否</div>
        </div>
        <div class="item border-b">
          <div class="name">发布时间</div>
          <div class="text">{{productDetail.product.origin_product_create_time | parseTime }}</div>
        </div>
        <img
          class="close"
          @click="()=>{this.showPopup = false}"
          src="../assets/goods/close_03.png"
          alt="#"
        />
        <div class="footer">
          <div class="btn" @click="()=>{this.showPopup = false}">完成</div>
        </div>
      </div>
    </van-popup>
  </div>
</template>

<script>
import { Swipe, SwipeItem, Popup } from "vant";
import { parseTime } from "@/utils";
import { mapGetters } from "vuex";
export default {
  components: {
    "van-swipe": Swipe,
    "van-swipe-item": SwipeItem,
    "van-popup": Popup,
  },
  // computed: {
  //   ...mapGetters(["productDetail"])
  // },
  data() {
    return {
      loadingFlag: false,
      current: 0,
      swiperList: [],
      showPopup: false,
      productDetail: {},
    };
  },
  created() {
    this.productDetail = JSON.parse(localStorage.getItem("productDetail"));
    if (this.productDetail.product.product_price.indexOf("¥") > -1) {
      this.productDetail.product.product_price = this.productDetail.product.product_price.slice(
        1,
        this.productDetail.product.product_price.length
      );
    }
    console.log("商品信息", this.productDetail);
  },
  // mounted() {
  //   this.$nextTick(function() {
  //     if (localStorage.getItem("product")) {
  //       this.product = JSON.parse(localStorage.getItem("product"));
  //     }
  //     console.log("商品信息", this.product);
  //   });
  // },
  methods: {
    onChange(index) {
      this.current = index;
    },
    handleBack() {
      this.$router.go(-1);
    },
  },
};
</script>

<style lang='scss' scoped>
.container {
  width: 100vw;
  min-height: 100vh;
  background-color: #f7f7f7;
  > .swiper {
    /deep/ .van-swipe-item {
      width: 100%;
      height: 7.63rem;
      img {
        width: 100%;
        height: 100%;
      }
    }
    .custom-indicator {
      position: absolute;
      right: 30px;
      bottom: 30px;
      width: 90px;
      height: 38px;
      line-height: 38px;
      text-align: center;
      color: #fff;
      background: rgba(0, 0, 0, 0.4);
      border-radius: 19px;
      font-size: 20px;
      letter-spacing: 2px;
      > span {
        font-size: 28px;
      }
    }
  }
  > .info {
    background-color: #fff;
    padding: 38px 30px 30px;
    margin-bottom: 20px;
    > .title {
      display: flex;
      justify-content: space-between;
      align-items: center;
      margin-bottom: 28px;
      > p {
        display: flex;
        font-size: 30px;
        font-weight: bolder;
        color: rgba(17, 17, 17, 1);
        > span {
          display: block;
          width: auto;
          height: 26px;
          line-height: 30px;
          padding: 0 2px;
          border: 2px solid #fd5f17;
          border-radius: 4px;
          font-size: 20px;
          font-weight: 400;
          color: rgba(254, 96, 24, 1);
          margin-right: 18px;
        }
      }
    }
    > .price {
      font-size: 50px;
      font-weight: 500;
      color: #fe6018;
      text-align: left;
      margin-bottom: 30px;
      > span {
        font-size: 30px;
        font-weight: 500;
        &:nth-of-type(2) {
          font-weight: bolder;
          font-size: 50px;
        }
      }
    }
    > .time_address {
      display: flex;
      justify-content: space-between;
      > p {
        font-size: 24px;
        font-weight: 400;
        color: rgba(177, 177, 177, 1);
        > img {
          vertical-align: middle;
          width: 24px;
          height: 24px;
          margin-bottom: 4px;
          margin-right: 8px;
        }
      }
    }
  }
  .info-item {
    display: flex;
    justify-content: flex-start;
    align-items: center;
    text-align: left;
    padding: 30px;
    background-color: #fff;
    > .name {
      width: 140px;
      margin-right: 56px;
      font-size: 28px;
      font-weight: 400;
      color: rgba(153, 153, 153, 1);
    }
    > .text {
      font-size: 28px;
      font-weight: 400;
      color: rgba(17, 17, 17, 1);
    }
  }
  > .num {
    margin-bottom: 20px;
  }
  > .detail {
    margin-bottom: 40px;
    > .detail-item {
      display: flex;
      justify-content: space-between;
      align-items: center;
      padding: 36px 30px 26px;
      background-color: #fff;
      font-size: 28px;
      font-weight: 400;
      color: rgba(17, 17, 17, 1);
      > .icon {
        color: #bcbcbc;
      }
    }
  }
  > .footer {
    position: fixed;
    left: 0;
    bottom: 0;
    z-index: 999;
    width: 100%;
    height: 120px;
    background: rgba(255, 255, 255, 1);
    padding-top: 16px;
    > .agent-btn {
      width: 670px;
      height: 88px;
      line-height: 88px;
      margin: 0 auto;
      font-size: 28px;
      font-weight: 400;
      color: rgba(255, 255, 255, 1);
      background: linear-gradient(
        90deg,
        rgba(255, 147, 3, 1),
        rgba(254, 96, 24, 1)
      );
      border-radius: 4px;
    }
  }
  /deep/ .van-popup--bottom {
    width: 100vw;
    border-radius: 10px 10px 0px 0px;
    overflow: hidden;
  }
  .popup-content {
    position: relative;
    > .close {
      position: absolute;
      top: 40px;
      right: 30px;
      width: 38px;
      height: 38px;
    }
    > .title {
      padding: 52px 0 26px;
      font-size: 28px;
      font-weight: 400;
      color: rgba(51, 51, 51, 1);
    }
    > .item {
      display: flex;
      justify-content: flex-start;
      align-items: center;
      padding: 32px;
      &.border-b {
        border-bottom: 1px solid #f2f2f2;
      }
      > .name {
        text-align: left;
        width: 120px;
        font-size: 28px;
        font-weight: 400;
        color: rgba(153, 153, 153, 1);
        margin-right: 80px;
        > .text {
          font-size: 28px;
          font-weight: 400;
          color: rgba(17, 17, 17, 1);
        }
      }
    }
    > .footer {
      width: 100%;
      padding: 16px 38px 16px 42px;
      > .btn {
        width: 670px;
        height: 88px;
        line-height: 88px;
        background: linear-gradient(
          90deg,
          rgba(255, 147, 3, 1),
          rgba(254, 96, 24, 1)
        );
        border-radius: 4px;
        font-size: 28px;
        font-weight: 400;
        color: rgba(255, 255, 255, 1);
        margin: 0 auto;
      }
    }
  }
}
</style>
